package com.vast.vastlcd.lcdAPI;

import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;

/**
 * Extension of {@link DataOutputStream} created to deal with the fact that 
 * x86 (the only currently supported host) is in LSB and Java is always 
 * in MSB.   
 */
public class LCDDataOutputStream extends DataOutputStream {

	/**
	 * Constructor.
	 * @param out The output stream to use.
	 */
	public LCDDataOutputStream(OutputStream out) {
		super(out);
	}
	
	/**
	 * Writes out a LSB 4-byte Integer byte-by-byte using Java which is 
	 * always in MSB mode.
	 * TODO: May need to deal with 64bit architecture.
	 * @param intToWrite The 4-byte integer to write out.
	 * @throws IOException Thrown if there is an error writing out
	 */
	public void writeLSBInt(int intToWrite) throws IOException {
		super.write((byte)(intToWrite));
		super.write((byte)(intToWrite >>> 8));
		super.write((byte)(intToWrite >>> 16));
		super.write((byte)(intToWrite >>> 24));		
	}

}
